package com.costeaalex.MIDlets.remote.lists;

import java.util.Vector;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.List;

import com.costeaalex.MIDlets.remote.BlueMIDlet;
import com.costeaalex.MIDlets.remote.canvas.RemoteCanvas;

public class InterfacesList implements CommandListener
	{
	
	private BlueMIDlet	midlet;
	public List list;
	private Command cmExit;
	private Command cmSelect;
	private Vector interfacesL;
	
	public InterfacesList(BlueMIDlet midl, Vector interfaces)
		{
		int i;
		midlet=midl;
		interfacesL=interfaces;
		list = new List("Select Interface", List.IMPLICIT);
		
		for(i=0; i<interfacesL.size(); i++)
			{
			list.insert(i,((RemoteCanvas) interfacesL.elementAt(i)).getName(), null);
			}

		cmExit=new Command("Exit", Command.EXIT, 1);
		cmSelect=new Command("Select", Command.SCREEN, 2);
		
		list.addCommand(cmExit);
		list.addCommand(cmSelect);
		list.setCommandListener(this);
		}

	public void commandAction(Command c, Displayable d)
		{
		
		if(c==cmExit)
			{
			midlet.shutDown();
			}
						
		if(c==cmSelect)
			{
			midlet.displayManager.advanceToChild(interfacesL.elementAt(list.getSelectedIndex()));
			((RemoteCanvas) interfacesL.elementAt(list.getSelectedIndex())).initialize();
			}
		}
	}
